package com.ljj.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy;

@Configuration
public class AppConfig {

    @Bean
    public ThreadPoolExecutor taskExecutor() {
        return new ThreadPoolExecutor(
                2,                    // 核心线程数
                4,                    // 最大线程数
                60L,                  // 空闲线程存活时间（秒）
                java.util.concurrent.TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(10), // 队列容量
                new CallerRunsPolicy()         // 拒绝策略
        );
    }
}